<template>
  <div class="homewrap">
    <div class="wrap">
      <img src="@/assets/images/banner.f559b49d.png" alt="" />
    </div>
    <div class="productbgc">
      <Title :titlename="jingpinname" :titleImg="jingpinImg"></Title>
      <List :productdata="jingpin"></List>
      <Title :titlename="remenname" :titleImg="remenImg" class="tilteMargin"></Title>
      <img src="@/assets/images/banner.4c6b6225.png" class="smallbanner" />
      <List :productdata="remen"></List>
    </div>
    <div class="wrap integralwrap">
      <Title titlename="积分攻略" :titleImg="require('@/assets/images/score.png')"></Title>
      <ul>
        <li>
          <img src="@/assets/images/integral-02.150d92a1.png" alt="" />
          <p>签到得积分</p>
          <div class="btn">去签到</div>
        </li>
        <li>
          <img src="@/assets/images/integral-03.9870f3f1.png" alt="" />
          <p>签到得积分</p>
          <div class="btn">去购课</div>
        </li>
        <li>
          <img src="@/assets/images/integral-02.150d92a1.png" alt="" />
          <p>签到得积分</p>
          <div class="btn">去推荐</div>
        </li>
        <li>
          <img src="@/assets/images/integral-03.9870f3f1.png" alt="" />
          <p>签到得积分</p>
          <div class="btn">去拼团</div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import Title from "@/components/home/Title";
import List from "@/components/home/List";

import { JingPinAPI, ReMenAPI } from "@/request/api.js";

export default {
  name: "HomeView",
  data() {
    return {
      jingpin: [], //精品的数据
      jingpinname: "", //精品的标题
      jingpinImg: require("@/assets/images/jingpin.png"), //精品图标
      remen: [], //热门的数据
      remenname: "", //热门的标题
      remenImg: require("@/assets/images/hot.png"), //热门图标
    };
  },
  components: {
    Title,
    List,
  },
  async created() {
    /*
      解决图片路径拼接的方式
      方式1：拦截器
      方式2：在main.js中设置全局变量，然后在其他组件可以直接跟组件data中的数据一样去调用
             在main.js中设置全局变量:Vue.prototype.imgBaseUrl = "http://sc.wolfcode.cn";
             在任意组件中调用: this.变量名 或者 {{变量名}} 来获取
    */
    // 精品推荐
    let jingPinRes = await JingPinAPI();
    if (jingPinRes.code == 0) {
      // 过滤出前4条
      this.jingpin = jingPinRes.data.data.records.filter(
        (item, index) => index < 4
      );
      this.jingpinname = jingPinRes.data.name;
    }

    // 热门兑换
    let reMenRes = await ReMenAPI();
    if (reMenRes.code == 0) {
      this.remen = reMenRes.data.data.records.filter(
        (item, index) => index < 6
      );
      this.remenname = reMenRes.data.name;
    }
  },
};
</script>

<style lang="less" scoped>
.homewrap {
  margin-bottom: 30px;

  .productbgc {
    background: #f5f5f5;
    margin-top: 30px;
    padding: 50px 0 56px;
    box-sizing: border-box;

    .smallbanner {
      margin:0 auto 30px;
      display: block;
    }

    .tilteMargin{
      margin-top: 50px;
    }
  }

  .integralwrap {
    padding-top: 44px;
    margin-bottom: 47px;

    ul {
      display: flex;
      justify-content: space-between;

      li {
        position: relative;
        font-family: SourceHanSansSC;
        color: #ffffff;
        width: 285px;
        height: 168px;

        p {
          font-size: 30px;
          font-weight: bold;
          position: absolute;
          left: 16px;
          top: 49px;
        }
        .btn {
          position: absolute;
          left: 18px;
          top: 88px;
          width: 96px;
          height: 27px;
          line-height: 27px;
          border: 1px solid #ffffff;
          font-size: 16px;
          font-weight: 300;
          text-align: center;
          box-sizing: border-box;
          cursor: pointer;
        }
      }
    }
  }
}
</style>